package com.foreknow.mapping;

import com.foreknow.bean.Admin;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂类MappingFactory
 */
public class MappingFactory {
    private static MappingFactory mappingFactory = null;
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String ADMIN_MAPPING = "adminMapping";
    public static final String GUESTBOOK_MAPPING = "guestbookMapping";

    private MappingFactory() {

    }

    public static MappingFactory getInstance() {
        if(mappingFactory==null){
            mappingFactory = new MappingFactory();
            mappingFactory.maps.put(ADMIN_MAPPING,new AdminMapping());
            mappingFactory.maps.put(GUESTBOOK_MAPPING, new GuestbookMapping());
            //      mappingFactory.maps.put(ADMIN_MAPPING,new UserMapping());
            //      mappingFactory.maps.put(ADMIN_MAPPING,new xxxMapping());
        }
        return mappingFactory;
    }

    /**
     * 根据key从Map容器中获取到xxxMapping对象
     * @param key
     * @return EntityMapping接口
     */
    public EntityMapping getMap(String key) {
        return maps.get(key); //获取到AdminMapping对象
    }

}